<template>
  <el-dialog title="修改项目信息" :visible.sync="dialogEditorVisible" width="50%" :before-close="handleClose">
    <el-form class="demo-form-inline" ref="form" :model="currentRow" label-width="100px">
      <el-form-item label="用户名">
        <el-input v-model="currentRow.username"></el-input>
      </el-form-item>
      <el-form-item label="密码">
        <el-input v-model="currentRow.password"></el-input>
      </el-form-item>
      <el-form-item label="手机号">
        <el-input v-model="currentRow.mobile"></el-input>
      </el-form-item>
      <el-form-item label="性别">
        <el-select v-model="currentRow.sex" placeholder="请选择">
        <el-option   label="男" value="男"></el-option>
        <el-option   label="女" value="女"></el-option>
      </el-select>
      </el-form-item>
      <el-form-item label="职位">
        <el-select v-model="currentRow.roleId" placeholder="请选择职位">
          <el-option v-for="v in  sysrole" :key="v.id"  :label="v.roleName" :value="v.id"></el-option>
        </el-select>
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="dialogEditorVisible = false">取 消</el-button>
      <el-button type="primary" @click="create">确 定</el-button>
    </span>
  </el-dialog>
</template>

<script>
import api from '../../../api'
import qs from 'qs'

export default {
  data() {
    return {
      dialogEditorVisible: false,
      eTypeList: [],
      tunnelList: [],
      fileList: [],
      currentRow: {},
      sysrole:[]
    }
  },
  mounted() {
    this.$bus.$on('onShowPersonEditor', (row) => {
      this.dialogEditorVisible = true
      this.currentRow = row
    })
    this.findBySysRole()
  },
  methods: {
    findBySysRole(){
      api.sysRolefindByAll().then(res=>{
        this.sysrole = res.data.data
      }).catch(err=>{
        console.log(err)
      })
    },
    handleClose(done) {
      this.$confirm('确认关闭？')
        .then((_) => {
          done()
        })
        .catch((_) => { })
    },
    create() {

      if(this.currentRow.password == ''){
        this.$message({
              type: 'fail',
              message: '请输入密码!'
            })
            return
      }


      api
        .personInfoupdate(qs.stringify(this.currentRow))
        .then((res) => {
          if (res.data.code == 2001) {
            this.$message({
              type: 'success',
              message: '更新成功!'
            })
            this.dialogEditorVisible = false
            this.$bus.$emit('onRefreshPerson', true)
          } else {
            this.$message({
              type: 'fail',
              message: '更新失败!'
            })
            this.dialogVisible = false
          }
        })
        .catch((err) => { })
    }
  }
}
</script>

<style scoped >
.avatar-uploader .el-upload {
  position: relative;
  overflow: hidden;
  cursor: pointer;
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
}

.avatar-uploader .el-upload:hover {
  border-color: #409eff;
}

.avatar-uploader-icon {
  width: 50px !important;
  height: 50px !important;
  font-size: 28px;
  line-height: 50px !important;
  color: #8c939d;
  text-align: center;
}

.avatar {
  display: block;
  width: 50px !important;
  height: 50px !important;
}

.imgbeforepad {
  padding-top: 0px !important;
}

.avatar-uploader .el-icon-plus {
  margin: 15px !important;
}
</style>